Ext.define('DCApp.controller.ListController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.list',

    getSelectedItem: function(){
        return this.getView().getSelectionModel().getSelection()[0] || false;
    },
    
     onNew: function() {
     	var vm = this.getViewModel();
     	var nd = vm.type.replace('list','detail');
    	this.redirectTo(nd + '/-1',false);
    },
   
    onDblClick: function(view, rec) {
    	var vm = this.getViewModel();
     	var nd = vm.type.replace('list','detail');
    	this.redirectTo(nd + '/'+ rec.id);

    },
    
    onRefreshClick: function() {
        this.getView().getStore().load();
    },
    
    onRel: function() {
    	var ds = this.getView().getStore();
    	var vm = this.getViewModel();
    	var title = this.getView().up('[cls=nav_pos]').title;
        var win = new Ext.window.Window({
        	width:500,
        	height:300,
        	layout:'fit',
        	modal:true,
        	viewModel: vm,
        	items:[{
        		 fieldName: vm.data.rel['fieldName'],
        		 xtype: 'multiselector',
        		 title:'选择'+title,
        		 store: ds,
                 search: vm.data.rel['search']
        		}
        	],   
        	plain: true,
            headerPosition: 'bottom'
        });
        win.show();
    },
    
    onDel: function() {
		var sels = this.getView().getSelectionModel().getSelection();
		if (sels.length == 0) {
			Ext.MessageBox.alert('操作提示', '请先选择待删除的条目', null, this);
			return;
		} else {
			Ext.MessageBox.confirm('确认删除', '您确定要删除选中的[' + sels.length + ']项?',
			function(btn, text) {
				if (btn != 'yes')
					return false;
	    		this.getView().getStore().getData().remove(sels);    				
			}, this);
		}    	
    }

});
